package com.qf.staff.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.common.base.result.RespResult;
import com.qf.staff.common.qo.SupplierQo;
import com.qf.staff.common.vo.SupplierVo;
import com.qf.staff.service.SupplierService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "供应商管理Api")
@RestController
@RequestMapping("/supplier")
public class SupplierController {
    @Resource
    SupplierService supplierSerice;

    /*
     *
     * */
    @ApiOperation("查询所有供应商信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码"),
            @ApiImplicitParam(name = "size", value = "条数"),
            @ApiImplicitParam(name = "size", value = "条数"),
            @ApiImplicitParam(name = "supplierName", value = "供应商名称"),
            @ApiImplicitParam(name = "phone", value = "供应商电话"),
            @ApiImplicitParam(name = "number", value = "排序 默认按id，2按销量，3按销售金额")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @GetMapping("/list")
    public RespResult<IPage<SupplierVo>> list(@RequestParam(defaultValue = "1") int page,
                                              @RequestParam(defaultValue = "10") int size,
                                              SupplierQo supplierQo,
                                              @RequestParam(defaultValue = "1") int number
    ) {
        return RespResult.success(supplierSerice.list(page, size, supplierQo, number));
    }


    @ApiOperation("根据id修改status为0是删除供应商信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "supplierId", value = "供应商id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/delete")
    public RespResult<Integer> delete(SupplierQo supplierQo) {
        return RespResult.success(supplierSerice.delete(supplierQo));
    }

    @ApiOperation("根据id修改status为0是批量删除供应商信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "deptId", value = "部门id")})
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @DeleteMapping("/deleteAll/{status}")
    public int deleteAll(@RequestBody List<Integer> ids, @PathVariable("status") int status) {
        return supplierSerice.deleteAll(ids, status);
    }

    @ApiOperation("根据id修改供应商信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "supplier_name", value = "供应商名称"),
            @ApiImplicitParam(name = "admin", value = "管理员"),
            @ApiImplicitParam(name = "phone", value = "手机号"),
            @ApiImplicitParam(name = "entry_number", value = "发布项目数"),
            @ApiImplicitParam(name = "money", value = "销售金额"),
            @ApiImplicitParam(name = "status", value = "0代表无效，1代表有效"),
    })
    @ApiResponses({@ApiResponse(code = 200, message = "成功")})
    @PutMapping("/modify")
    public RespResult<Integer> modify(SupplierQo supplierQo) {
        return RespResult.success(supplierSerice.modify(supplierQo));
    }

    @ApiOperation("增加供应商信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "supplierName", value = "供应商名称"),
            @ApiImplicitParam(name = "admin", value = "管理员"),
            @ApiImplicitParam(name = "phone", value = "手机号"),
            @ApiImplicitParam(name = "money", value = "销售金额"),
            @ApiImplicitParam(name = "status", value = "0代表无效，1代表有效"),
    })
    @PostMapping("/add")
    public RespResult<Integer> add(SupplierQo supplierQo) {
        return RespResult.success(supplierSerice.add(supplierQo));
    }

}
